package com.rongke.utils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

/**
 * Created by chengwenwen on 2016/12/20.
 */
public class OrderUtils {
    private static long orderNum = 0l;
    private static String date ;


    /**
     * 生成订单编号
     * @return
     */
    public static synchronized String getOrderNo() {
        String str = new SimpleDateFormat("yyyyMMddHHmm").format(new Date());
        if(date==null||!date.equals(str)){
            date = str;
            orderNum  = 0l;
        }
        orderNum ++;
        long orderNo = Long.parseLong((date)) * 10000;
        orderNo += orderNum;
        return orderNo+"";
    }

    /**
     * 开团号
     * @return
     */
    public static synchronized String butTogetherCode(int size) {
        String str="";
        Random r = new Random();
        for(int i=0;i<size;i++){
            str+=r.nextInt(10);
        }
        return str;
    }

    public static void main(String args[]){
        System.out.print(butTogetherCode(6));
    }

    /**
     * 余额支付交易订单编号
     * @return
     */
    public static synchronized String getBalancePayNo() {
        String str = new SimpleDateFormat("yyyyMMddHHmm").format(new Date());
        if(date==null||!date.equals(str)){
            date = str;
            orderNum  = 0l;
        }
        orderNum ++;
        long orderNo = Long.parseLong((date)) * 10000;
        orderNo += orderNum;
        return "xx4009772001"+orderNo+"";
    }
}
